package com.link.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * 判断是否是window系统或者Mac系统
 * @author 郭闪
 * @date 2019/12/30
 */
public class OperatingSystemCondition implements Condition {

    /**
     * 覆盖父类方法，判断当前操作系统是否是window系统或者Mac系统，如果是返回false
     * @author 郭闪
     * @date 2019/12/30
     * @param context
     * @param annotatedTypeMetadata
     *
     */
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata annotatedTypeMetadata) {
        Environment environment = context.getEnvironment();

        String property = environment.getProperty("os.name");
        if (property.toLowerCase().contains("windows") || property.toLowerCase().contains("mac os")) {
            return false;
        }
        return true;
    }
}
